package com.mashibing.constraints;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

public class VehicleTypeValidator implements ConstraintValidator<VehicleTypeCheck,String> {
    List<String> vehicleTypeList = null;

    @Override
    public void initialize(VehicleTypeCheck constraintAnnotation) {
        vehicleTypeList = Arrays.asList(constraintAnnotation.vehicleTypeElements());
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println("汽车类型校验开始");
        return vehicleTypeList.contains(s);
    }
}
